import http from '../../utils/request/request'

// 新增养殖加工订单
export function AddOrderBreed(params) {
    return http({
        url: `/order/orderBreed`,
        method: 'post',
        data: params
    })
}
// 修改养殖加工订单
export function EditOrderBreed(params) {
    return http({
        url: `/order/orderBreed`,
        method: 'put',
        data: params
    })
}

// 分页查询加工订单
export function getOrderBreed(limit, size) {
    return http({
        url: `/order/orderBreed/${limit-1}/${size}`,
        method: 'get'
    })
}

// 按收获人的名字、订单id、收货号码分页查询加工订单
export function getOrderBreedByKey(limit, size, key) {
    return http({
        url: `/order/orderBreed/${limit-1}/${size}/${key}`,
        method: 'get'
    })
}

// 删除加工订单
export function delOrderBreed(orderProcessingId) {
    return http({
        url: `/order/orderBreed/${orderProcessingId}`,
        method: 'delete'
    })
}

// 获取batchId
export function getBatchId(current, size) {
    return http({
        url: `/breed/farming/${current}/${size}`,
        method: 'get'
    })
}

// 获取客户收货地址
export function getCustomer(limit, size, key) {
    return http({
        url: `/order/personalCustomer/${limit}/${size}/${key}`,
        method: 'get'
    })
}

// 获取企业收货地址
export function getCompanyCustomer(limit, size, key) {
    return http({
        url: `/order/companyCustomer/${limit}/${size}/${key}`,
        method: 'get'
    })
}

// 列属性
export function getColumns(vm) {
    return [
        // 表头数据
        { name: "订单id", show: true, prop: "id" }, //show
        { name: "创建时间", show: true, prop: "gmtCreate" },
        {
            name: "订单状态", show: true, prop: "orderStatus", format: (val) => {
                return val == 1 ? '未送达' : '已送达'
            }
        }, //show
        {
            name: "产品",
            show: false,
            prop: "productId",
            select: {
                options: [],
                label: "name",
                value: "id",
                change: (value, curOps) => {
                    vm.form.productName = curOps.name;
                },
            }
        }, //select
        { name: "产品名", show: false, prop: "productName" }, //select
        { name: "数量(只)", show: false, prop: "productCount" }, //count
        { name: "产品重量(公斤)", show: false, prop: "productWeight" }, //count
        { name: "总金额(元)", show: false, prop: "productAmount" }, //count
        {
            name: "目标方类型",
            show: false,
            prop: "targetCustomerType",
            select: {
                // 选项
                options: [
                    { label: "个人", value: "1" },
                    { label: "企业", value: "2" },
                ],
                // 事件
                change: vm.setTargetList,
            },
        }, //select
        {
            name: "目标",
            show: true,
            prop: "targetId",
            select: {
                options: [],
                value: "id",
                label: "customerName",
                change: (value, curOps) => {
                    vm.form.targetName = curOps.customerName;
                    vm.getArea(curOps.customerName)
                },
            },
        }, //select
        {
            name: "所属批次",
            show: false,
            prop: "batchId",
            select: {
                options: [],
                label: "baseName",
                value: "id",
                change: (value, curOps) => {
                    vm.form.batchId = curOps.id;
                },
            }
        }, //select
        {
            name: "物流公司",
            show: true,
            prop: "logisticsCompany",
            select: {
                options: [
                    { label: "中通", value: "中通" },
                    { label: "申通", value: "申通" },
                    { label: "圆通", value: "圆通" },
                    { label: "顺丰", value: "顺丰" },
                    { label: "京东", value: "京东" },
                    { label: "韵达", value: "韵达" },
                    { label: "极兔", value: "极兔" },
                    { label: "百世", value: "百世" },
                ],
            },
        }, //select
        { name: "物流编号", show: false, prop: "logisticsId" },
        { name: "收货联系电话", show: false, prop: "receivePhone" },
        { name: "目标名称", show: false, prop: "targetName" }, //select
        {
            name: "供应商",
            show: false,
            prop: "sourceId",
            select: {
                options: [],
                label: "supplierName",
                value: "id",
            },
        }, //select
        // {
        //     name: "订单状态",
        //     show: true,
        //     prop: "orderStatus",
        //     select: {
        //         options: [
        //             { label: "未送达", value: "1" },
        //             { label: "已送达", value: "2" }
        //         ],
        //     },
        // }, //select
        { name: "收货地址城市", show: false, prop: "addressCity" }, //select
        { name: "收货地址省份", show: false, prop: "addressProvince" }, //select
        { name: "收货地址纬度", show: false, prop: "receiveLatitude" }, //select
        { name: "收货地址经度", show: false, prop: "receiveLongitude" }, //select
        { name: "收货地址", show: false, prop: "receiveAddress" }, //select
    ]
}

// 表单验证规则
export const rules = {
    batchId: [
        { required: true, message: "请选择所属批次", trigger: "blur" },
    ],
    logisticsCompany: [
        { required: true, message: "请填写物流公司", trigger: "blur" },
    ],
    logisticsId: [
        { required: true, message: "请填写物流编号", trigger: "blur" },
    ],
    productAmount: [
        { required: true, message: "请填写总金额(元)", trigger: "blur" },
    ],
    productCount: [
        { required: true, message: "请填写数量(只)", trigger: "blur" },
    ],
    productName: [
        { required: true, message: "请填写产品名", trigger: "blur" },
    ],
    productWeight: [
        { required: true, message: "请填写产品重量(公斤)", trigger: "blur" },
    ],
    receiveAddress: [
        { required: true, message: "请填写收货地址", trigger: "blur" },
    ],
    receivePhone: [
        { required: true, message: "请填写收货联系电话", trigger: "blur" },
    ],
    targetCustomerType: [
        { required: true, message: "请填写目标方类型", trigger: "blur" },
    ],
    targetName: [
        { required: true, message: "请填写目标名称", trigger: "blur" },
    ],
}
